# -*- coding: utf-8 -*-
"""
@Time ： 2023/7/5 21:43
@Auth ： 叶东宇
@File ：huadongchuangkouwithdandiaoque.py
"""
from collections import deque
class MyQue:
    def __init__(self):
        self.queue = deque()

    def pop(self, num):
        if self.queue and num == self.queue[0]:
            self.queue.popleft()

    def push(self, num):
        while self.queue and num > self.queue[-1]:
            self.queue.pop()
        self.queue.append(num)

    def maxValue(self):
        return self.queue[0]

class Solution:
    def maxSlidingWindow(self, nums, k):
        que = MyQue()
        result = []
        for i in range(k):
            que.push(nums[i])
        result.append(que.maxValue())
        for i in range(k, len(nums)):
            que.pop(nums[i-k])
            que.push(nums[i])
            result.append(que.maxValue())
        return result

if __name__ == "__main__":
    k = 3
    nums = [3,3,-1,-3,5,3,6,7]
    solution = Solution()
    print(solution.maxSlidingWindow(nums, k))
    